package com.jtlrm.ckd.mvp.view.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.base.sdk.util.ImageUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jtlrm.ckd.R;
import com.jtlrm.ckd.entity.NewsEntity;
import com.jtlrm.ckd.entity.SuiFangPaiBanEntity;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuLayout;

/**
 *
 */
public class AddSuiFangAdapter extends BaseQuickAdapter<SuiFangPaiBanEntity, BaseViewHolder> {

    public AddSuiFangAdapter() {
        super(R.layout.suifang_select_huanzhe);
    }

    private UpdateSelect updateSelect;

    public void setUpdateSelect(UpdateSelect updateSelect) {
        this.updateSelect = updateSelect;
    }

    @Override
    protected void convert(BaseViewHolder helper, final SuiFangPaiBanEntity item) {
        ImageUtil.loadCircleAvatarImage((ImageView) helper.getView(R.id.avatar), item.getHeadPicture());
        helper.setText(R.id.name, item.getName());
        helper.setText(R.id.sex, item.getSex());
        helper.setText(R.id.age, item.getAge() + "岁");
        helper.setText(R.id.last_time, "上次随访:" + (item.getLastVisitTime() == null ? "" : item.getLastVisitTime()));
        helper.setText(R.id.next_time, "下次随访:" + (item.getVisitTime() == null ? "" : item.getVisitTime()));
        if ("短信".equals(item.getRegisterType() + "")) {
            ((ImageView) helper.getView(R.id.register_type)).setImageResource(R.drawable.manager_messgae_icon);
        } else {
            ((ImageView) helper.getView(R.id.register_type)).setImageResource(R.drawable.manager_phone_icon);
        }
        final CheckBox checkBox = helper.getView(R.id.checkbox);
        if (item.isSelect()) {
            checkBox.setChecked(true);
        } else {
            checkBox.setChecked(false);
        }
        helper.getView(R.id.container).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkBox.setChecked(!item.isSelect());
                item.setSelect(!item.isSelect());
                if (updateSelect != null) {
                    updateSelect.update();
                }
            }
        });
    }

    public interface UpdateSelect {
        void update();
    }
}
